
# Toolchain prefix (i.e arm-elf -> arm-elf-gcc.exe)
#export TCHAIN_PATH=~/Dropbox/devel/tools/CC/gcc/arm7/gcc-compiler-x64
export TCHAIN_PATH=~/Dropbox/devel/tools/CC/gcc/gcc-arm-none-eabi-4_7-2013q2

TCHAIN = $(TCHAIN_PATH)/bin/arm-none-eabi



LIBNAME	= usbstack

# Select your target
#TARGET = LPC214x
TARGET = LPC23xx

# If you are using port B on the LPC2378 uncomment out the next line
#LPC2378_PORT = -DLPC2378_PORTB
#DEB = DEBUG
DEB = NO_DEBUG

# Package definitions
PKG_NAME	= target
DATE		= $$(date +%Y%m%d)

# Tool definitions
CC      = $(TCHAIN)-gcc
LD      = $(TCHAIN)-ld -v
AR      = $(TCHAIN)-ar
AS      = $(TCHAIN)-as
CP      = $(TCHAIN)-objcopy
OD		  = $(TCHAIN)-objdump
RM		= rm
TAR	= tar

CFLAGS  = -I./ -I../ -c -W -Wall -Os -g -D$(DEB) -D$(TARGET) $(LPC2378_PORT) -mcpu=arm7tdmi
ARFLAGS = -rcs

LIBSRCS = usbhw_lpc.c usbcontrol.c usbstdreq.c usbinit.c
LIBOBJS = $(LIBSRCS:.c=.o)

#all: depend lib examples
all: depend lib #examples

clean:
	$(RM) -f $(LIBNAME).a $(LIBOBJS) .depend
	make -C examples clean

examples:
	make -C examples

# build lib
lib: $(LIBNAME).a

$(LIBNAME).a: $(LIBOBJS)
	$(AR) $(ARFLAGS) $@ $^

# Builds release tar file
dist: clean
	cd .. && $(TAR) --exclude={CVS,cvs,.svn} -cvzf $(PKG_NAME)-$(DATE).tar.gz $(PKG_NAME)

# recompile if the Makefile changes
$(LIBOBJS): Makefile

# dependency checking
depend: $(LIBSRCS)
	$(CC) $(CFLAGS) -MM $^ > .depend || rm -f .depend

# phony targets
.PHONY: all clean examples depend

-include .depend
